package com.znsd.zl.sys.audit.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mchange.v1.util.ArrayUtils;
import com.mchange.v1.util.ListUtils;
import com.znsd.zl.sys.audit.dao.IAuditDao;
import com.znsd.zl.sys.audit.entity.AuditEntity;
import com.znsd.zl.sys.audit.service.IAuditService;
import com.znsd.zl.sys.audit.vo.req.AuditEntityVO;
import com.znsd.zl.utils.PageUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jbb
 * @date 2020-08-17 11:38:51
 */
@Service("auditService")
public class AuditServiceImpl extends ServiceImpl<IAuditDao, AuditEntity> implements IAuditService {

    /**
     * 分页条件查询方法
     * @param params ：分页的条件
     * @return PageUtils ：封装的结果集对象
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params,Integer page,Integer limit) {
        params.remove("t");
        List<AuditEntityVO> list = getBaseMapper().queryPage(params,page==null?0:(page-1)*limit,limit==null?10:limit);

        System.out.println(list);
        IPage p=new Page();
        p.setRecords(list);
        p.setCurrent(page);
        p.setTotal(getBaseMapper().queryPageCount(params));
        return new PageUtils(p);
    }

    /**
     * 选择性的修改那个字段的值
     * @param map：修改的新值存放对象
     * @param id：要修改的ID
     * @return integer ：1成功，0失败
     */
    @Override
    public Integer selectUpdate(Map<String, Object> map, Integer id) {
        Object type = map.remove("type");
        String condition = "1";
        if (condition.equals(type)){
            Object houseId = map.remove("houseId");
            Object titleDeed = map.remove("title_deed");
            String images = (String)map.remove("images");
            Object createTime = map.get("update_time");
            Object operator = map.get("operator");
            String[] split = images.split(",");
            List<String> list = Arrays.asList(split);
            Object facility = map.remove("facility");
            Object house = map.remove("house");
            getBaseMapper().updateHouseTitleDeed(houseId,titleDeed,house,facility);
            getBaseMapper().saveHouseCover(houseId,list,createTime,operator);
        }
        return getBaseMapper().selectUpdate(map,id);
    }

    @Override
    public Integer saveHouseCover(String houseId, List list, String createTime, String operator) {
        return getBaseMapper().saveHouseCover(houseId,list,createTime,operator);
    }


}
